
package ProOF.apl.problems.real.functions;

import ProOF.com.LinkerNodes;
import ProOF.com.LinkerParameters;
import ProOF.com.LinkerResults;
import ProOF.com.LinkerValidations;
import ProOF.com.language.Node;

/**
 *
 * @author Hossomi
 */
public abstract class aRealFunction extends Node {
	public abstract int		dimension();
	public abstract double	min( int i );
	public abstract double	max( int i );
	public abstract double	f( double x[] ) throws Exception;
	
    public void check( double x[] ) throws Exception {
        if (x.length != dimension())
            throw new Exception("Wrong number of variables");
        
        for (int i = 0; i < dimension(); i++) {
            if (x[i] < min(i) || x[i] > max(i))
                throw new Exception("x[" + i + "] out of bounds (" + min(i) + " < " + x[i] + " < " + max(i) + ")");
        }
    }
    
    public void adjust( double x[] ) throws Exception {
        if (x.length != dimension())
            throw new Exception("Wrong number of variables");
        
        for (int i = 0; i < dimension(); i++) {
            if (x[i] < min(i))
                x[i] = min(i);
            else if (x[i] > max(i))
                x[i] = max(i);
        }
    }
    
	@Override
	public void services(LinkerNodes link) throws Exception {

	}

	@Override
	public void parameters(LinkerParameters link) throws Exception {
		
	}

	@Override
	public void load() throws Exception {
		
	}

	@Override
	public void start() throws Exception {
		
	}

	@Override
	public boolean validation(LinkerValidations link) throws Exception {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	@Override
	public void results(LinkerResults link) throws Exception {
		
	}
}
